package com.lwy.goods.controller;

import com.github.pagehelper.PageInfo;
import com.lwy.common.Result;
import com.lwy.common.StatusCode;
import com.lwy.goods.pojo.TbSku;
import com.lwy.goods.service.impl.TbSkuServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

//商品controller控制层
@RestController
@RequestMapping("sku")
public class TbSkuController {

    @Resource
    TbSkuServiceImpl tbSkuService;

    //分页查询列表
    @RequestMapping("list")
    public Result<PageInfo<TbSku>> list(String name,String brand_name,Integer pageNum, Integer pageSize){
        PageInfo<TbSku> page = tbSkuService.page(name,brand_name,pageNum, pageSize);
        return new Result<PageInfo<TbSku>>(true, StatusCode.OK,"商品查询",page);
    }

    @RequestMapping("save")
    public Result<List<TbSku>> save(TbSku tbSku) throws ParseException {
        int save = tbSkuService.saveTbsku(tbSku);
        return new Result<List<TbSku>>(true, StatusCode.OK,"商品新增",save);
    }

    @RequestMapping("edit")
    public Result<List<TbSku>> edit(TbSku tbSku) throws ParseException {
        int update = tbSkuService.updateTbSku(tbSku);
        return new Result<List<TbSku>>(true, StatusCode.OK,"商品编辑",update);
    }
    @RequestMapping("findId")
    public TbSku findId(Integer tid){
        return tbSkuService.getById(tid);
    }

    @RequestMapping("del")
    public Result<List<TbSku>> del(Integer id){
        boolean del = tbSkuService.removeById(id);
        return new Result<List<TbSku>>(true, StatusCode.OK,"删除",del);
    }
}
